@echo off
echo.
echo Ordina generic WSP installer 
echo.

set PACKAGE="CollectAndCrop.wsp"

set COMMAND=%1
set SITEURL=%2
set PATH=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%PATH% 

if not exist %PACKAGE% goto :wspMissing
if (%SITEURL%)==() goto :argumentError
if (%COMMAND%)==() goto :argumentError

if /i ('%COMMAND%')==('add')     goto :command_add
if /i ('%COMMAND%')==('delete')  goto :command_delete
if /i ('%COMMAND%')==('deploy')  goto :command_deploy
if /i ('%COMMAND%')==('retract') goto :command_retract
if /i ('%COMMAND%')==('install') goto :command_install
if /i ('%COMMAND%')==('update')	 goto :command_update
goto :unknownCommand

:command_add
echo *** Adding solution %PACKAGE%
stsadm -o addsolution -filename %PACKAGE%
goto end

:command_delete
echo *** Adding solution %PACKAGE%
stsadm -o deletesolution -name %PACKAGE%
goto end

:command_deploy
echo *** Deploying solutions
stsadm -o deploysolution -name %PACKAGE% -immediate -url %SITEURL% -allowGacDeployment -allowCasPolicies -force
echo *** Waiting for deployment to complete
stsadm -o execadmsvcjobs
goto end

:command_retract
echo *** Retracting solutions
stsadm -o retractsolution -name %PACKAGE% -immediate -url %SITEURL%
echo *** Waiting for deployment to complete
stsadm -o execadmsvcjobs
goto end

:command_install
echo *** Adding solution %PACKAGE%
stsadm -o addsolution -filename %PACKAGE%
goto command_deploy

:command_update
echo *** Upgrading solution %PACKAGE%
stsadm -o upgradesolution -filename %PACKAGE% -name %PACKAGE% -immediate -allowcaspolicies -allowGacDeployment
echo *** Waiting for upgrade to complete
stsadm -o execadmsvcjobs
goto end

:unknownCommand
echo ### Command %COMMAND% NOT FOUND ###
echo .
goto argumentError

:wspMissing
echo ### %PACKAGE% NOT FOUND ###
echo .
goto end

:argumentError
echo ### usage %PACKAGE:~0,-4%.cmd command url ###
echo command:  add     - add solution
echo           update  - update solution
echo           delete  - delete solution
echo           deploy  - deploy solution
echo           retract - retract solution
echo           install - add + deploy solution
echo .
goto end

:end
echo.
pause